package com.simpleim.starter.command;

import org.springframework.stereotype.Service;

import java.util.Scanner;

@Service
public class ChatCommand implements BaseCommand{

    private String userId;

    private String message;

    public static final String KEY = "2";

    @Override
    public void exec(Scanner scanner) {
        System.err.println("请用(userid:message的格式输入账号：)");
        while (true) {
            String inputCon = scanner.next();
            String[] strs = inputCon.split(":");
            if (strs.length != 2) {
                System.err.println("格式不正确，请重新输入");
                continue;
            }

            userId = strs[0];
            message = strs[1];
            // 发送数据到服务端
            return;
        }
    }

    @Override
    public String type() {
        return KEY;
    }

    @Override
    public String title() {
        return "聊天";
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
